﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FRL.DebtChased.Silverlight.Library
{

	/// <summary>
	/// Declaration of WebsiteMenuItemCtrl class
	/// </summary>
	public partial class WebsiteMenuItemCtrl : UserControl
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		private DebtChasedWebsiteMenuCtrl.eMenuItem m_menuItemId = DebtChasedWebsiteMenuCtrl.eMenuItem.NotSet;
		public DebtChasedWebsiteMenuCtrl.eMenuItem MenuItemId
		{
			get { return m_menuItemId; }
			set { m_menuItemId = value; }
		}

		private bool m_bIsChild = false;
		public bool IsChild
		{
			get { return m_bIsChild; }
			set { m_bIsChild = value; _setupControls(); }
		}

		private bool m_bIsLink = true;
		public bool IsLink
		{
			get { return m_bIsLink; }
			set { m_bIsLink = value; _setupControls(); }
		}

		private bool m_bIsHighlighted = false;
		public bool IsHighlighted
		{
			get { return m_bIsHighlighted; }
			set { 
				m_bIsHighlighted = value;
				if (m_bIsHighlighted)
					LayoutRoot.Background = this.Resources["SecondaryBrush"] as SolidColorBrush;
				else
					LayoutRoot.Background = new SolidColorBrush(Colors.White);
			}
		}

		public string Text
		{
			get { return tbLabel.Text; }
			set { tbLabel.Text = value; hypLink.Content = value; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		public WebsiteMenuItemCtrl()
		{

			// Load xaml resources
			InitializeComponent();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Show/hide controls
			tbLabel.Visibility = m_bIsLink ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
			hypLink.Visibility = m_bIsLink ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
			// pathTriangle.Visibility = m_bIsChild ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

			// Set indentation
			if (m_bIsChild)
			{
				colIndent.Width = new GridLength(20, GridUnitType.Pixel);
				tbLabel.FontWeight = FontWeights.Normal;
				hypLink.FontWeight = FontWeights.Normal;				
			}
			else
			{
				colIndent.Width = new GridLength(0, GridUnitType.Pixel);
				tbLabel.FontWeight = FontWeights.Bold;				
				hypLink.FontWeight = FontWeights.Bold;				
			}

		}

		private void hypLink_Click(object sender, RoutedEventArgs e)
		{
#if DEBUG
			Debug.Assert(m_menuItemId != DebtChasedWebsiteMenuCtrl.eMenuItem.NotSet);
#endif // #if DEBUG

			// Inform the parent window
			DebtChasedWebsiteMenuCtrl parentCtrl = (sender as FrameworkElement).FindParent(typeof(DebtChasedWebsiteMenuCtrl)) as DebtChasedWebsiteMenuCtrl;
			parentCtrl.MenuItemClicked(m_menuItemId);

		}

	}

}
